<?php

declare (strict_types = 1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://doc.hyperf.io
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */
namespace App\Controller;

use App\Constants\ErrorCode;
use App\Exception\BusinessException;
use App\Lib\Niutrans\Xunfei;
use App\Service\Auth\ModuleService;
use App\Utils\GRPCClient;
use Hyperf\Utils\Codec\Json;
use Pb\Params;

class IndexController extends AbstractController
{
    public function index()
    {
        $arrToken = \App\Lib\JwtToken::authorizations(
            [
                "uid" => 1, //记录的userid的信息
                "id" => 1, //记录的userid的信息
                'account' => 'admin', // 用户账号
                'name' => '小bei',
                'company_id' => '1',
            ],

            config('web.admin_jwt_key')
        );
        return [
            'token' => $arrToken,
        ];
        $client = new GRPCClient();
        $request = new Params();
        $request->setRequest(Json::encode(['appkey' => '123']));
        $request->setController(ModuleService::class);
        $request->setMethod('getModules');

        list($reply, $status) = $client->curdClient($request);
        if ($reply->getErrCode() == 0) {
            $data = $reply->getData();
            return $data;
        } else {
            throw new BusinessException(ErrorCode::ERR_BUESSUS, $reply->getMsg());
        }
        $arrToken = \App\Lib\JwtToken::authorizations(
            [
                "uid" => 1, //记录的userid的信息
                "id" => 1, //记录的userid的信息
                'account' => 'admin', // 用户账号
                'name' => '小bei',
                'company_id' => '1',
            ],
            config('web.admin_jwt_key')
        );
        return [
            'token' => $arrToken,
        ];
        $obj = new Xunfei();
        return $obj->xfyun(['text' => '中华人民共和国于1949年成立', 'to' => 'en']);

    }
}
